using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using CubeWars___Demolition.PhysicObjects;
using Physics.Physics;
using Physics.Collision;

namespace CubeWars___Demolition.GamePlay
{
    public static class CreateScene
    {
        public static void createFloor(Game1 game)
        {
            createImmovable(game, new Vector3(500, 0.1f, 500), new Vector3(-5, -10.01f, -50));
            createImmovable(game, new Vector3(0.1f, 50, 1000), new Vector3(-25, 0, -50));
        }

        public static void CreateScene1(Game1 game)
        {
            createImmovable(game, new Vector3(20, 0.1f, 20), new Vector3(0, 0, 0));
            Model boxModel = game.Content.Load<Model>("Models/box");
            for (int j = 0; j <= 5; j++)
            {
                for (int i = 0; i <= 5; i++)
                {
                    BoxObject obj = new BoxObject(game, boxModel, new Vector3(2f, 2f, 2f), Matrix.Identity, new Vector3(i * 2.5f - 5, 1 + j * 2.2f, 0));
                    game.Components.Add(obj);
                    obj.DrawOrder = 1;
                }
            }
        }

        public static void CreateScene2(Game1 game, int dim)
        {
            Model boxModel = game.Content.Load<Model>("Models/box");
            createImmovable(game, new Vector3(20, 0.1f, 10), new Vector3(0, -15.01f, -0));

            for (int j = 0; j <= dim; j++)
            {
                for (int i = 0; i <= dim; i++)
                {
                    BoxObject obj = new BoxObject(game, boxModel, new Vector3(2f, 2f, 2f), Matrix.Identity, new Vector3(i * 2.5f - 5, -10 + j * 2.2f, 0));
                    game.Components.Add(obj);
                    obj.DrawOrder = 1;
                }
            }

        }

        public static void createImmovable(Game1 game, Vector3 dimension, Vector3 position)
        {
            Model boxModel = game.Content.Load<Model>("Models/box");
            BoxObject obj = new BoxObject(game, boxModel, dimension, Matrix.Identity, position);
            game.gameState.floorSkins.Add(obj.PhysicsSkin);
            obj.PhysicsBody.Immovable = true;
            game.Components.Add(obj);
            obj.DrawOrder = 1;
        }

        public static void createWall1(Game1 game, int dimension)
        {

        }

        public static void destroyScene(Game1 game)
        {
            List<PhysicObject> toBeRemoved = new List<PhysicObject>();
            foreach (GameComponent gc in game.Components)
            {
                if (gc is PhysicObject)
                {
                    PhysicObject physObj = gc as PhysicObject;
                    toBeRemoved.Add(physObj);
                }
            }

            foreach (PhysicObject physObj in toBeRemoved)
            {
                physObj.PhysicsBody.DisableBody();
                game.Components.Remove(physObj);

                //seems to be very important. Hold one of the demo keys and
                //watch your memory.
                physObj.Dispose();
            }
        }
        
    }
}
